home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-05-18 | 5.1 KB | 205 lines | [TEXT/GEOL] |
- Item 5421661 14-May-90 08:25PDT
-
- From: TESLER Tesler, Larry
-
- To: MACAPP.TECH$ MacApp Technical
-
- cc: TESLER Tesler, Larry
-
- Sub: Using THINK'S C & PASCAL
-
- I converted a large MacApp program with C modules from MPW to THINK PASCAL & C.
-
- To get it to work, below are listed some of the things I had to do that were
- not apparent from the documentation I read.
-
-
- PROBLEM 1:
-
- In INTERFACE of one unit:
- TYPE
- CategoryHandle = ^CategoryPtr;
- CategoryPtr = ^CategoryArray;
- CategoryArray = ARRAY[OffScreenPixel] OF PaletteIndex;
-
- In IMPLEMENTATION of another unit:
- cat := CategoryHandle(NewPermHandle(256*SIZEOF(cat^^[0])));
-
- Problem:
- 256*SIZEOF(cat^^[0])) calculates the wrong answer.
-
- Workaround:
- cat := CategoryHandle(NewPermHandle(256*LONGINT(512)));
-
- Note:
- I'm not sure whether the following would have worked:
- cat := CategoryHandle(NewPermHandle(256*LONGINT(SIZEOF(cat^^[0]))));
-
-
- PROBLEM 2:
- In INTERFACE OF a unit:
- ProfileResultArray = array [ 0 .. kMaxLogsPerProfile - 1 ] of EXTENDED;
-
- Problem:
- Constant expression kMaxLogsPerProfile-1 is not allowed.
-
- Workaround:
- ProfileResultArray = array[0..1] of EXTENDED;
-
-
- PROBLEM 3:
- In INTERFACE OF a unit:
- TYPE
- RecordOfUnwrappedViews = record
- unwrappedView: TUnwrappedView;
- colorScaleView: TColorScaleView;
- depthScaleView: TDepthScaleView;
- azimuthScaleView: TAzimuthScaleView;
- end;
- ...
- TUnwrappedView = OBJECT(TOffScreenView)
- fAssociatedViews: RecordOfUnwrappedViews;
-
- Problem:
- Forward reference to TUnwrappedView from RecordOfUnwrappedViews illegal
- and vice versa
-
- Workaround:
- Deleted line:
- unwrappedView: TUnwrappedView;
- Moved type RecordOfUnwrappedViews after type TUnwrappedView
-
-
- PROBLEM 4:
- In INTERFACE OF a unit:
- type
- HistogramList = record
- numberOfHistograms: longint;
- histogramSize: longint;
- thehistogramdata: packed array[0..2147483] of longint;
- end;
- HistogramListP = ^HistogramList;
- HistogramListH = ^HistogramListP;
-
- Problem:
- 2147483 not allowed as upper bound
- (even though only HistogramListH is referenced later)
-
- Workaround:
- thehistogramdata: packed array[0..1000] of longint;
-
-
- PROBLEM 5:
- In a THINK C module:
- Tried to call atan, sqrt, hypot, malloc, free, memccpy, fflush, etc.
-
- Problem:
- C and Pascal libraries differ in contents
- C and Pascal libraries have duplicate symbols
-
- Workaround:
- Added to one of my Pascal units:
- procedure take_atan (var x, y: double);
- begin
- y := arctan(x);
- end;
-
- procedure take_sqrt (var x, y: double);
- begin
- y := sqrt(x);
- end;
-
- Defined my own atanf, sqrtf, hypot, memccpyf as follows:
- pascal extern void take_atan(double* x, double* y);
-
- double atanf(double x)
- {
- double z;
- take_atan(&x, &z);
- return(z);
- }
-
- pascal extern void take_sqrt(double* x, double* y);
-
- double sqrtf(double x)
- {
- double z;
- take_sqrt(&x, &z);
- return(z);
- }
-
- double hypot(double x, double y)
- {
- return(sqrtf(x*x+y*y));
- }
-
- char* memccpyf(char *dest, char *source, char c, size_t n)
- {
- long i;
- for(i=0;i<n;i++)
- if((dest[i] = source[i])==c)
- return(&dest[i+1]);
- return(NULL);
- }
-
- Called NewPermPtr and DisposPtr instead of malloc and free, after declaring:
- pascal extern long NewPermPtr(long nbytes);
-
- Used MacHeaders to compile my C modules in THINK C.
-
- Got rid of all console and file I/O calls for now.
-
- Made my own C LibraryProject by copying and modifying ANSI-A4 as follows:
- Copied and modified stdio.c as follows to avoid a duplicate __CLOSE message:
- /*
- int
- __close(fp)
- FILE *fp;
- {
- return((*fp->proc)(fp, 2));
- }
- */
- Used the modified stdio.c in the modified ANSI-A4 LibraryProject
- Built a Library from the modified ANSI-A4 LibraryProject
- Added that Library to my Pascal Project along with a Library made from
- my C modules
-
-
- PROBLEM 6:
- In a THINK C module:
- long max_num_attrs; { initialized to 40 later }
- #define MAXFIELDWIDTH 16
- typedef struct one_attribute
- {
- char type_code,element_size,attribute[MAXFIELDWIDTH+1],
- unit[MAXFIELDWIDTH+1],*val_ptr;
- long num_elements;
- } attr_record, (*attr_ptr)[];
- attr_ptr cblt_table;
- cblt_table=(attr_ptr)NewPermPtr(sizeof(attr_record)*max_num_attrs);
-
- Problem:
- "sizeof(attr_record)*max_num_attrs" generates a very large number
-
- Workaround:
- cblt_table=(attr_ptr)NewPermPtr(2000);
-
- Note:
- I'm not sure whether the following would have worked:
- cblt_table=(attr_ptr)NewPermPtr(sizeof(attr_record)*(long)max_num_attrs);
-
-
- MISCELLANEOUS C CHANGES:
- Changed all "int" to "long".
- Changed all "extended" to "long double".
- Would have changed all "double" to "short double" if I'd had any.
- Had to stop using a conditionally compiled macro name as a type name.
-
-
- MISCELLANEOUS PASCAL CHANGES:
- Eliminated all constant expressions used as:
- array bounds
- range bounds (m..n)
- right sides of constant declarations
-
-